package com.hucai;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.hucai.vo.AddressVo;
import com.hucai.vo.GaodeVo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sujinglong
 * @date 2019/9/3
 * @description TODO
 */
public class MatherAddress {
    public static void main(String[] args) {
        //高德地图不存在的地址
        List<String> gaoDeNotExistList = new ArrayList();

        //读取我们系统的地址
        String content = FileUtil.readUtf8String("address.json");
        List<AddressVo> addressVos =  JSONUtil.toList(JSONUtil.parseArray(content), AddressVo.class);
        Map<String,AddressVo> addressVoMap = new HashMap();
        for(AddressVo addressVo : addressVos){
            String key = addressVo.getAd_code()+"/"+addressVo.getName();
            addressVoMap.put(key,addressVo);
        }

        //读取高德地图的地址
        content = FileUtil.readUtf8String("gaode.json");
        GaodeVo gaodeVo =  JSONUtil.toBean(content,GaodeVo.class);
        mather(gaoDeNotExistList,addressVoMap,gaodeVo);

        //读取高德地图不存在的数据
        System.out.println("============读取高德地图不存在的数据================");
        System.out.println(JSONUtil.toJsonStr(gaoDeNotExistList));

        //读取我们系统不存在的数据
        System.out.println("============读取我们系统不存在的数据================");
        System.out.println(JSONUtil.toJsonStr(addressVoMap));

    }

    private static void mather(List<String> gaoDeNotExistList,Map<String,AddressVo> addressVoMap,GaodeVo gaodeVo){
        String key = gaodeVo.getAdcode()+"/"+gaodeVo.getName();
        if(addressVoMap.containsKey(key)){
            addressVoMap.remove(key);
        }else{
            gaoDeNotExistList.add(key);
        }

        for(GaodeVo vo: gaodeVo.getDistricts()){
            mather(gaoDeNotExistList,addressVoMap,vo);
        }
    }
}
